package inc.gome.dynamic.datasource.netty;

import io.netty.channel.socket.nio.NioSocketChannel;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author sujizhou
 * @Date 2021/12/9
 * @Desc 客户端请求调用
 */
public class ClientTest {



    public static void main(String[] args) throws IOException {


        InetSocketAddress localhost = new InetSocketAddress("localhost", 9090);
        //TODO  这里模拟多线程回调方法 会不会没有这个问题？？？？？

       for (int i = 0; i <5 ; i++) {
           int finalI = i;
           //高并发下
           new Thread(()->{
               try {
                   //代理对象中实现的请求体封装
                   RequestBody requestBody=new RequestBody();
                   requestBody.setFlag("car"+ finalI);
                   requestBody.setRequestId((long) finalI);
                   CompletableFuture<Object> cf=ClientFactory.transport(requestBody);


                   String  o = (String) cf.get();  //获取执行结果

                   System.out.println("获取回调执行结果："+o);

               } catch ( InterruptedException | ExecutionException e) {
                   e.printStackTrace();
               }
           }).start();
       }
            System.in.read();

    }
}
